﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace VSCode;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        
        // Set window state
        this.WindowState = WindowState.Normal;
        
        // Handle window state changes
        this.StateChanged += (s, e) =>
        {
            UpdateMaximizeRestoreButton();
        };
    }

    private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ClickCount == 2)
        {
            ToggleWindowState();
        }
        else
        {
            this.DragMove();
        }
    }

    private void MinimizeButton_Click(object sender, RoutedEventArgs e)
    {
        this.WindowState = WindowState.Minimized;
    }

    private void MaximizeButton_Click(object sender, RoutedEventArgs e)
    {
        ToggleWindowState();
    }

    private void CloseButton_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }

    private void ToggleWindowState()
    {
        if (WindowState == WindowState.Maximized)
        {
            WindowState = WindowState.Normal;
        }
        else
        {
            WindowState = WindowState.Maximized;
        }
    }

    private void UpdateMaximizeRestoreButton()
    {
        if (WindowState == WindowState.Maximized)
        {
            MaximizeIcon.Data = Geometry.Parse("M0,2 H8 V10 H0 Z M2,2 V0 H10 V8 H8");
            this.BorderThickness = new Thickness(8);
        }
        else
        {
            MaximizeIcon.Data = Geometry.Parse("M0,0 H10 V10 H0 Z");
            this.BorderThickness = new Thickness(1);
        }
    }
}